本文共 645 字,大约阅读时间需要 2 分钟。
//Andy’s First Dictionary, UVa 10815 //输入一个文本,找出所有不同的单词(连续的字母序列) //按字典序从小到大输出,单词不区分大小写。
#include#include #include #include using namespace std;set dict; //string集合int main() { string s, buf; while (cin >> s) { for (int i = 0; i < s.size(); i++) { if (isalpha(s[i])) s[i] = tolower(s[i]); else s[i] = ' '; } stringstream ss(s); //创建字符串流 while (ss >> buf) dict.insert(buf); //从ss中得到buf并插入set中 } for (set ::iterator it = dict.begin(); it != dict.end(); it++) //运用迭代器 cout << *it << endl; return 0;} //以上代码利用了set中元素以从小到大排好序这一性质
转载地址:http://uoipz.baihongyu.com/